package com.cskaoyan.service.aftersale;

import com.cskaoyan.bean.MallAfterSale;
import com.cskaoyan.bean.MallAfterSaleExample;
import com.cskaoyan.bean.MallOrderGoods;
import com.cskaoyan.bean.MallOrderGoodsExample;
import com.cskaoyan.mapper.MallAfterSaleMapper;
import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.vo.BaseData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: mjm
 * @Date: 2021/11/30
 * @Time: 20:31
 * @Description:
 */
@Service
public class AfterSaleServiceImpl implements AfterSaleService {
    @Autowired
    MallAfterSaleMapper mallAfterSaleMapper;


    @Override
    public BaseData aftersaleList(PageBo param,String aftersaleSn, Short status,Integer orderId) {

        //在查询之前使用分页
        PageHelper.startPage(param.getPage(), param.getLimit());

        //List<User> users = userMapper.select(username, mobile, param.getSort(), param.getOrder());

        MallAfterSaleExample example = new MallAfterSaleExample();
        example.setOrderByClause(param.getSort() + " " + param.getOrder());
        MallAfterSaleExample.Criteria criteria = example.createCriteria();

        if(aftersaleSn != null && !"".equals(aftersaleSn)){
            criteria.andAftersaleSnLike("%" + aftersaleSn + "%");
        }

        if(orderId != null && !"".equals(orderId)){
            criteria.andOrderIdEqualTo(orderId);
        }


        if(status != null && !"".equals(status)){
            criteria.andStatusEqualTo(status);
        }
        //逻辑删除的售后信息不显示
        criteria.andDeletedEqualTo(false);
        List<MallAfterSale> mallAfterSales = mallAfterSaleMapper.selectByExample(example);
        PageInfo info = new PageInfo(mallAfterSales);
        long total = info.getTotal();
        return BaseData.list(mallAfterSales,total);
    }

    @Override
    public int batchRecept(ArrayList<Integer> ids) {

        int affectedRows = mallAfterSaleMapper.batchRecept(ids);
        return affectedRows;
    }

    @Override
    public int batchReject(ArrayList<Integer> ids) {
        int affectedRows = mallAfterSaleMapper.batchReject(ids);
        return affectedRows;
    }
}
